package com.dragon.modules.yuegou.client.wechat_mini.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 微信小程序返回码枚举
 * 
 * @author liuwu
 * @date 2019年7月5日
 *
 */
public enum MiniCode {

	SYSTEM_BUSY(-1, "系统繁忙，此时请开发者稍候再试"),
	OK(0, "请求成功"),
	
	/*订阅消息*/
	INVALID_TEMPLATE_ID(40037, "订阅模板id为空不正确"),
	USER_REFUSED(43101, "用户拒绝接受消息，如果用户之前曾经订阅过，则表示用户取消了订阅关系"),
	INVALID_TEMPLATE_PARAMS(47003, "模板参数不准确，可能为空或者不满足规则，errmsg会提示具体是哪个字段出错"),
	INVALID_PAGE(41030, "page路径不正确，需要保证在现网版本小程序中存在，与app.json保持一致"),
	
	RISKY_CONTENT(87014, "内容含有违法违规内容"),
	INVALID_SECRET_TOKEN(40001, "获取access_token时AppSecret错误，或者access_token无效。请开发者认真比对AppSecret的正确性，或查看是否正在为恰当的公众号调用接口"),
	INVALID_GRANT_TYPE(40002, "不合法的凭证类型"),
	INVALID_OPENID(40003, "不合法的OpenID，请开发者确认OpenID（该用户）是否已关注公众号，或是否是其他公众号的OpenID"),
	INVALID_MEDIA_TYPE(40004, "不合法的媒体文件类型"),
	INVALID_FILE_TYPE(40005, "不合法的文件类型"),
	INVALID_FILE_SIZE(40006, "不合法的文件大小"),
	INVALID_MEDIA_ID(40007, "不合法的媒体文件id"),
	INVALID_MSG_TYPE(40008, "不合法的消息类型"),
	INVALID_IMAGE_SIZE(40009, "不合法的图片文件大小"),
	INVALID_VOICE_SIZE(40010, "不合法的语音文件大小"),
	INVALID_VIDEO_SIZE(40011, "不合法的视频文件大小"),
	INVALID_THUMB_SIZE(40012, "不合法的缩略图文件大小"),
	INVALID_APPID(40013, "不合法的AppID，请开发者检查AppID的正确性，避免异常字符，注意大小写"),
	INVALID_ACCESS_TOKEN(40014, "不合法的access_token，请开发者认真比对access_token的有效性（如是否过期），或查看是否正在为恰当的公众号调用接口"),
	INVALID_MENU_TYPE(40015, "不合法的菜单类型"),
	INVALID_MENU_NUM(40016, "不合法的菜单个数"),//这里官方文档上有错误？
	INVALID_BUTTON_NUM(40017, "不合法的按钮个数"),
	INVALID_BUTTON_NAME_LENGTH(40018, "不合法的按钮名字长度"),
	INVALID_BUTTON_KEY_LENGTH(40019, "不合法的按钮KEY长度"),
	INVALID_BUTTON_URL_LENGTH(40020, "不合法的按钮URL长度"),
	INVALID_MENU_VERSION(40021, "不合法的菜单版本号"),
	INVALID_CHILD_MENU_LEVEL(40022, "不合法的子菜单级数"),
	INVALID_CHILD_MENU_BUTTON_NUM(40023, "不合法的子菜单按钮个数"),
	INVALID_CHILD_MENU_BUTTON_TYPE(40024, "不合法的子菜单按钮类型"),
	INVALID_CHILD_MENU_BUTTON_NAME_LENGTH(40025, "不合法的子菜单按钮名字长度"),
	INVALID_CHILD_MENU_BUTTON_KEY_LENGTH(40026, "不合法的子菜单按钮KEY长度"),
	INVALID_CHILD_MENU_BUTTON_URL_LENGTH(40027, "不合法的子菜单按钮URL长度"),
	INVALID_MENU_DEFINED_USER(40028, "不合法的自定义菜单使用用户"),
	INVALID_OAUTH_CODE(40029, "不合法的oauth_code"),
	INVALID_REFRESH_TOKEN(40030, "不合法的refresh_token"),
	INVALID_OPENID_LIST(40031, "不合法的openid列表"),
	INVALID_OPENID_LIST_LENGTH(40032, "不合法的openid列表长度"),
	INVALID_REQUEST_CHAR(40033, "不合法的请求字符，不能包含\\uxxxx格式的字符"),
	INVALID_REQUEST_ARGUMENT(40035, "不合法的参数"),
	INVALID_REQUEST_FORMAT(40038, "不合法的请求格式"),
	INVALID_URL_LENGTH(40039, "不合法的URL长度"),
	INVALID_GROUP_ID(40050, "不合法的分组id"),
	INVALID_GROUP_NAME(40051, "分组名字不合法"),
	INVALID_GROUP_NAME_2(40117, "分组名字不合法"),//?
	INVALID_MEDIA_ID_LENGTH(40118, "media_id大小不合法"),
	INVALID_BUTTON_TYPE(40119, "button类型错误"),
	INVALID_BUTTON_TYPE_2(40120, "button类型错误"),//?
	INVALID_MEDIA_ID_TYPE(0, "不合法的media_id类型"),
	INVALID_WXID(40132, "微信号不合法"),
	INVALID_IMAGE_FORMAT(40137, "不支持的图片格式"),
	MISS_ACCESS_TOKEN(41001, "缺少access_token参数"),
	MISS_APPID(41002, "缺少appid参数"),
	MISS_REFRESH_TOKEN(41003, "缺少refresh_token参数"),
	MISS_SECRET(41004, "缺少secret参数"),
	MISS_MEDIA_DATA(41005, "缺少多媒体文件数据"),
	MISS_MEDIA_ID(41006, "缺少media_id参数"),
	MISS_CHILD_MENU_DATA(41007, "缺少子菜单数据"),
	MISS_OAUTH_CODE(41008, "缺少oauth code"),
	MISS_OPENID(41009, "缺少openid"),
	EXPIRED_ACCESS_TOKEN(42001, "access_token超时，请检查access_token的有效期，请参考基础支持-获取access_token中，对access_token的详细机制说明"),
	EXPIRED_REFRESH_TOKEN(42002, "refresh_token超时"),
	EXPIRED_OAUTH_CODE(42003, "oauth_code超时"),
	USER_PASSWORD_MODIFIED(42007, "用户修改微信密码，accesstoken和refreshtoken失效，需要重新授权"),
	REQUIRE_GET(43001, "需要GET请求"),
	REQUIRE_POST(43002, "需要POST请求"),
	REQUIRE_HTTPS(43003, "需要HTTPS请求"),
	REQUIRE_SUBSCRIBE(43004, "需要接收者关注"),
	REQUIRE_FRIENDSHIP(43005, "需要好友关系"),
	EMPTY_MEDIA_FILE(44001, "多媒体文件为空"),
	EMPTY_POST(44002, "POST的数据包为空"),
	EMPTY_APP_MSG_CONTENT(44003, "图文消息内容为空"),
	EMPTY_FILE_MSG_CONTENT(44004, "文本消息内容为空"),
	OVER_LIMIT_MEDIA_LENGTH(45001, "多媒体文件大小超过限制"),
	OVER_LIMIT_MSG_LENGTH(45002, "消息内容超过限制"),
	OVER_LIMIT_TITLE_LENGTH(45003, "标题字段超过限制"),
	OVER_LIMIT_DESCRIPTION_LENGTH(45004, "描述字段超过限制"),
	OVER_LIMIT_LINK_LENGTH(45005, "链接字段超过限制"),
	OVER_LIMIT_IMG_URL_LENGTH(45006, "图片链接字段超过限制"),
	OVER_LIMIT_VOICE_PLAY_LENGTH(45007, "语音播放时间超过限制"),
	OVER_LIMIT_APP_MSG_LENGTH(45008, "图文消息超过限制"),
	OVER_LIMIT_API_ACCESS(45009, "接口调用超过限制"),
	OVER_LIMIT_MENU_NUM(45010, "创建菜单个数超过限制"),
	OVER_LIMIT_RESPONSE_TIMEOUT(45015, "回复时间超过限制"),
	MODIFY_FORBIDDEN_FOR_SYSTEM_GROUP(45016, "系统分组，不允许修改 "),
	OVER_LIMIT_GROUP_NAME_LENGTH(45017, "分组名字过长"),
	OVER_LIMIT_GROUP_NUM(45018, "分组数量超过上限"),
	OVER_LIMIT_CUSTOMSERVICE_MSG(45047, "客服接口下行条数超过上限"),
	NOT_FOUND_MEDIA_DATA(46001, "不存在媒体数据"),
	NOT_FOUND_MENU_VERSION(46002, "不存在的菜单版本"),
	NOT_FOUND_MENU_DATA(46003, "不存在的菜单数据"),
	NOT_FOUND_USER(46004, "不存在的用户"),
	PARSE_ERROR(47001, "解析JSON/XML内容错误"),
	API_NOT_PERMIT(48001, "api功能未授权，请确认公众号已获得该接口，可以在公众平台官网-开发者中心页中查看接口权限 "),
	API_FORBIDDEN(48004, "api接口被封禁，请登录mp.weixin.qq.com查看详情 "),
	API_NOT_PERMIT_BY_USER(50001, "用户未授权该api"),
	FORBIDDEN(50002, "用户受限，可能是违规后接口被封禁 "),
	INVALID_PARAMETER(61451, "参数错误(invalid parameter)"),
	INVALID_KF_ACCOUNT(61452, "无效客服账号(invalid kf_account) "),
	KF_ACCOUNT_EXSITED(61453, "客服帐号已存在(kf_account exsited) "),
	INVALID_KF_ACOUNT_LENGTH(61454, "客服帐号名长度超过限制(仅允许10个英文字符，不包括@及@后的公众号的微信号)(invalid kf_acount length) "),
	ILLEGAL_CHARACTER_IN_KF_ACCOUNT(61455, "客服帐号名包含非法字符(仅允许英文+数字)(illegal character in kf_account)"),
	KF_ACCOUNT_COUNT_EXCEEDED(61456, "客服帐号个数超过限制(10个客服账号)(kf_account count exceeded)"),
	INVALID_KF_ACCOUNT_HEAD_IMG_FILE_TYPE(61457, "无效头像文件类型(invalid file type)"),
	SYSTEM_ERROR(61450, "系统错误(system error) "),
	INVALID_DATE_FORMAT(61500, "日期格式错误"),
	NOT_FOUND_CONDITIONAL_MENU(65301, "不存在此menuid对应的个性化菜单 "),
	NOT_FOUND_RELATED_USER(65302, "没有相应的用户 "),
	MISS_DEFAULT_MENU(65303, "没有默认菜单，不能创建个性化菜单 "),
	MISS_MATCH_RULE(65304, "MatchRule信息为空"),
	CONDITIONAL_MENU_COUNT_EXCEEDED(65305, "个性化菜单数量受限"),
	CONDITIONAL_MENU_NOT_SUPPORT(65306, "不支持个性化菜单的帐号"),
	CONDITIONAL_MENU_EMPTY(65307, "个性化菜单信息为空"),
	MISS_BUTTON_TYPE(65308, "包含没有响应类型的button"),
	CONDITIONAL_MENU_CLOSED(65309, "个性化菜单开关处于关闭状态"),
	EMPTY_COUNTRY(65310, "填写了省份或城市信息，国家信息不能为空"),
	EMPTY_PROVINCE(65311, "填写了城市信息，省份信息不能为空"),
	INVALID_COUNTRY(65312, "不合法的国家信息"),
	INVALID_PROVINCE(65313, "不合法的省份信息"),
	INVALID_CITY(65314, "不合法的城市信息"),
	REDIRECT_URL_COUNT_EXCEEDED(65316, "该公众号的菜单设置了过多的域名外跳（最多跳转到3个域名的链接）"),
	INVALID_URL(65317, "不合法的URL"),
	CODE9001001(9001001, "POST数据参数不合法"),
	CODE9001002(9001002, "远端服务不可用"),
	CODE9001003(9001003, "Ticket不合法"),
	CODE9001004(9001004, "获取摇周边用户信息失败"),
	CODE9001005(9001005, "获取商户信息失败"),
	CODE9001006(9001006, "获取OpenID失败"),
	CODE9001007(9001007, "上传文件缺失"),
	CODE9001008(9001008, "上传素材的文件类型不合法"),
	CODE9001009(9001009, "上传素材的文件尺寸不合法"),
	CODE9001010(9001010, "上传失败"),
	CODE9001020(9001020, "帐号不合法"),
	CODE9001021(9001021, "已有设备激活率低于50%，不能新增设备"),
	CODE9001022(9001022, "设备申请数不合法，必须为大于0的数字"),
	CODE9001023(9001023, "已存在审核中的设备ID申请"),
	CODE9001024(9001024, "一次查询设备ID数量不能超过50"),
	CODE9001025(9001025, "设备ID不合法"),
	CODE9001026(9001026, "页面ID不合法"),
	CODE9001027(9001027, "页面参数不合法"),
	CODE9001028(9001028, "一次删除页面ID数量不能超过10"),
	CODE9001029(9001029, "页面已应用在设备中，请先解除应用关系再删除"),
	CODE9001030(9001030, "一次查询页面ID数量不能超过50"),
	CODE9001031(9001031, "时间区间不合法"),
	CODE9001032(9001032, "保存设备与页面的绑定关系参数错误"),
	CODE9001033(9001033, "门店ID不合法"),
	CODE9001034(9001034, "设备备注信息过长"),
	CODE9001035(9001035, "设备申请参数不合法"),
	CODE9001036(9001036, "查询起始值begin不合法 ");
	
	private final int code;

	private final String remark;

	private MiniCode(int code, String remark) {
		this.code = code;
		this.remark = remark;
	}

	public int getCode() {
		return code;
	}

	public String getRemark() {
		return remark;
	}
	
	private static final Map<Integer, MiniCode> CODE_MAP = new HashMap<>();
	static{
		MiniCode[] codes = MiniCode.values();
		for(MiniCode code : codes){
			CODE_MAP.put(code.getCode(), code);
		}
	}
	
	public static MiniCode from(int errcode){
		return CODE_MAP.get(errcode);
	}

}
